//
//  Common.cpp
//  ConcurrentMemoryPool
//
//  Created by 张木林 on 5/3/25.
//

#include "Common.hpp"
#include "ThreadCache.hpp"

static void* ConcurrentAlloc(size_t size)
{
    //通过TLS 每个线程无锁的获取自己的专属的ThreadCache对象
    
    if(pTLSThreadCache == nullptr)
    {
        pTLSThreadCache = new ThreadCache;
    }
    
    cout<<std::this_thread::get_id()<<":"<<pTLSThreadCache<<endl;
    return pTLSThreadCache->Allocate(size);
}


static void ConcurrentFree(void* ptr,size_t size)
{
    assert(pTLSThreadCache);
    
    pTLSThreadCache->Deallocate(ptr, size);
}

